package o;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ProgressBar;
import androidx.recyclerview.widget.RecyclerView.s;
import com.huawei.appgallery.foundation.card.base.normal.bean.NormalCardBean;
import com.huawei.appgallery.foundation.ui.css.CSSView;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import com.huawei.appgallery.horizontalcard.api.card.BaseHorizontalItemCard;
import java.util.ArrayList;
import java.util.List;

public class clr extends androidx.recyclerview.widget.RecyclerView.a<s> {
    private int ʽ;
    protected Context ˊ;
    protected chy ˋ;
    private cls ˎ;
    protected int ˏ;
    protected clp<? extends NormalCardBean> ॱ;
    private boolean ॱॱ = false;
    private b ᐝ;

    public interface b {
        boolean ˊ();
    }

    public class a extends s {
        protected View ʻॱ;
        protected BaseHorizontalItemCard ॱˋ = null;
        final /* synthetic */ clr ॱᐝ;

        public a(clr o_clr, View view, BaseHorizontalItemCard baseHorizontalItemCard) {
            this.ॱᐝ = o_clr;
            super(view);
            this.ʻॱ = view;
            this.ॱˋ = baseHorizontalItemCard;
        }

        public BaseHorizontalItemCard ˊˊ() {
            return this.ॱˋ;
        }
    }

    class d extends s {
        private ProgressBar ʻॱ;
        final /* synthetic */ clr ॱˋ;

        public d(clr o_clr, View view) {
            this.ॱˋ = o_clr;
            super(view);
            this.ʻॱ = (ProgressBar) view.findViewById(o.clo.b.ˎ);
        }
    }

    public clr(Context context, clp<? extends NormalCardBean> o_clp__extends_com_huawei_appgallery_foundation_card_base_normal_bean_NormalCardBean, cls o_cls, b bVar, boolean z) {
        this.ˊ = context;
        this.ॱ = o_clp__extends_com_huawei_appgallery_foundation_card_base_normal_bean_NormalCardBean;
        this.ˎ = o_cls;
        this.ᐝ = bVar;
        this.ॱॱ = z;
    }

    public void ʼ(int i) {
        this.ˏ = i;
    }

    public int ˏ() {
        if (this.ॱ == null || this.ॱ.ॱ() == null) {
            return 0;
        }
        return (int) Math.ceil((double) (((float) this.ॱ.ॱ().size()) / ((float) this.ॱ.ᐝ())));
    }

    public int ˎ(int i) {
        if (this.ॱ == null || this.ॱ.ॱ() == null) {
            return 0;
        }
        NormalCardBean normalCardBean = (NormalCardBean) this.ॱ.ॱ().get(i);
        if (normalCardBean == null) {
            return 0;
        }
        return normalCardBean.ﾞ();
    }

    public long ˏ(int i) {
        if (this.ॱॱ) {
            return (long) i;
        }
        return super.ˏ(i);
    }

    public s ˎ(ViewGroup viewGroup, int i) {
        if (i == 0) {
            try {
                s ˎ = ˎ(viewGroup);
                if (ˎ == null) {
                    return ˎ;
                }
                View view = ˎ.ˊ;
                if (this.ॱ.ˏ() == null) {
                    return ˎ;
                }
                CSSView.wrap(view, this.ॱ.ˏ()).render();
                return ˎ;
            } catch (Exception e) {
                cll.ˎ.ˊ("CardViewHolder", e.toString());
                return null;
            }
        } else if (i == 1) {
            return new d(this, LayoutInflater.from(viewGroup.getContext()).inflate(o.clo.d.ॱ, viewGroup, false));
        } else {
            return null;
        }
    }

    private a ˎ(ViewGroup viewGroup) throws Exception {
        int ʻ = this.ॱ.ʻ();
        Class ˏ = cib.ˏ(this.ॱ.ʻ());
        if (ˏ == null) {
            cll.ˎ.ˊ("CardViewHolder", "Don't support card type:" + ʻ);
            return null;
        }
        Object newInstance = ˏ.getConstructor(new Class[]{Context.class}).newInstance(new Object[]{this.ˊ});
        if (newInstance instanceof BaseHorizontalItemCard) {
            BaseHorizontalItemCard baseHorizontalItemCard = (BaseHorizontalItemCard) newInstance;
            View inflate = LayoutInflater.from(viewGroup.getContext()).inflate(baseHorizontalItemCard.ˋ(), viewGroup, false);
            if (MinimumFactory.getBoolValue(ContentManager.getInstant().getContext())) {
                inflate.setLayoutDirection(1);
            }
            baseHorizontalItemCard.ˏ(inflate);
            baseHorizontalItemCard.ˉ().setClickable(true);
            baseHorizontalItemCard.ॱ(ॱ());
            return new a(this, inflate, baseHorizontalItemCard);
        }
        cll.ˎ.ˊ("CardViewHolder", "not instance of BaseHorizontalItemCard");
        return null;
    }

    public void ॱ(s sVar, int i) {
        if (sVar instanceof a) {
            a aVar = (a) sVar;
            this.ʽ = aVar.ॱˋ.ᐝ();
            int ᐝ = this.ॱ.ᐝ();
            if (ᐝ > 1) {
                int size = this.ॱ.ॱ().size();
                List arrayList = new ArrayList();
                for (int i2 = 0; i2 < ᐝ; i2++) {
                    int i3 = (i * ᐝ) + i2;
                    if (i3 == size) {
                        break;
                    }
                    arrayList.add((CardBean) this.ॱ.ॱ().get(i3));
                }
                aVar.ॱˋ.ˋ(arrayList);
                aVar.ॱˋ.ˋ(this.ॱ);
                aVar.ॱˋ.ᐝ(i);
            } else {
                aVar.ॱˋ.ˏ((CardBean) this.ॱ.ॱ().get(i));
                aVar.ॱˋ.ˋ(this.ॱ);
                aVar.ॱˋ.ᐝ(i);
            }
            ˊ(i, aVar);
        } else if (sVar instanceof d) {
            d dVar = (d) sVar;
            LayoutParams layoutParams = (LayoutParams) dVar.ʻॱ.getLayoutParams();
            layoutParams.setMarginEnd(this.ˎ.ˊ());
            if (this.ʽ > 0) {
                layoutParams.gravity = -1;
                layoutParams.topMargin = (this.ʽ - layoutParams.height) / 2;
            }
            dVar.ʻॱ.setIndeterminate(true);
        }
    }

    private void ˊ(int i, a aVar) {
        MarginLayoutParams marginLayoutParams = (MarginLayoutParams) aVar.ʻॱ.getLayoutParams();
        if (marginLayoutParams != null) {
            ॱ(i, marginLayoutParams);
            aVar.ʻॱ.setLayoutParams(marginLayoutParams);
        }
    }

    private void ॱ(int i, MarginLayoutParams marginLayoutParams) {
        if (this.ᐝ != null && this.ᐝ.ˊ() && i == ˏ() - 2) {
            marginLayoutParams.setMarginEnd(this.ˎ.ˊ());
        } else {
            marginLayoutParams.setMarginEnd(0);
        }
        if (i == 0) {
            marginLayoutParams.setMarginStart(this.ˎ.ˊ());
            return;
        }
        if (i == ˏ() - 1) {
            marginLayoutParams.setMarginEnd(this.ˎ.ˊ());
        }
        marginLayoutParams.setMarginStart(this.ˎ.ˋ());
    }

    public chy ॱ() {
        return this.ˋ;
    }

    public void ˎ(chy o_chy) {
    }
}
